# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Federico Cuello <fedux@fedux.com.ar>

pkgname=redmine
pkgver=5.0.6
pkgrel=1
pkgdesc="A flexible project management web application written using Ruby on Rails framework."
arch=('loong64' 'x86_64')
url="https://www.redmine.org"
license=('GPL2')
depends=('ruby' 'imagemagick' 'libxml2' 'libxslt')
makedepends=('mariadb-libs' 'postgresql-libs' 'sqlite' 'systemd')
optdepends=('apache: A supported application server'
            'nginx: A supported application server'
            'mysql: MySQL database support'
            'postgresql: PostgreSQL database support'
            'sqlite: SQLite database support')
source=("$url/releases/$pkgname-$pkgver.tar.gz"
	"Gemfile.local"
	"redmine.service")
sha512sums=('fa0b56ba2b24db9a752ae3cc977f2ef56c33ee4fe99154bfd2c5a449c3bc5f926f000002f23426ae4578a11d8f30121ae8707e39800168379baf546c5224e5ee'
            '1943883fdc5479f8acb4c256108b6ae054360eb7298b696bc3e16995dac0e51529b4a9f4c8e9158645a15d7b90fdcdaedb4502986a8a6dc4015671fae6861b6e'
            '0e2ebbe34e096935977ad72448b345a8c4b050fbee24ad035cbab872447cad24efd24240a4e0ae5f9ee0bd098b5737305162affa91431ffa28d1bc86b334a3f9')

build() {
    cd "$srcdir"/redmine-$pkgver

    cp "${srcdir}"/Gemfile.local Gemfile.local
    bundle config set force_ruby_platform true
    bundle config build.nokogiri --use-system-libraries
#    bundle config set without 'development test'
#    bundle config set no-cache 'true'
#    bundle config set deployment 'true'
    bundle lock
    bundle install --no-cache --deployment --without development test
}

package() {
    install -dm 755 "$pkgdir"/usr/share/webapps/

    rm "$srcdir"/redmine-$pkgver/vendor/bundle/ruby/3*/extensions/*/*/*/{mkmf.log,gem_make.out}
    rm -rf "$srcdir"/redmine-$pkgver/vendor/bundle/ruby/3*/gems/*/ext/

    cp -a --no-preserve=ownership "$srcdir"/redmine-$pkgver "$pkgdir"/usr/share/webapps/redmine

    install -Dm0644 "${srcdir}"/redmine.service "${pkgdir}"/usr/lib/systemd/system/redmine.service

    cd "$pkgdir"/usr/share/webapps/redmine
    rm -rf files log
    install -dm0755 -o http -g http "$pkgdir"/var/lib/redmine/files
    install -dm0755 -o http -g http "$pkgdir"/var/log/redmine
    mv tmp "$pkgdir"/var/lib/redmine/tmp
    chown -R http:http "$pkgdir"/var/lib/redmine/tmp
    ln -s /var/log/redmine log
    ln -s /var/lib/redmine/files files
    ln -s /var/lib/redmine/tmp tmp
}
